/*
* jlb
*/
package com.jlb.pay.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.pay.entity.PayMothed;
import com.jlb.pay.service.PayMothedSV;

/**
 * 支付方式分类 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/payMothed")
@Slf4j
@Api(value = "支付方式分类控制器", description = "支付方式分类控制器")
public class PayMothedCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private PayMothedSV payMothedSV;

    /**
     * 查询PayMothed一个详情信息
     *
     * @param id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询PayMothed一个详情信息", notes = "查询PayMothed一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(Long id, String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        PayMothed payMothed = payMothedSV.load(id, code);
        log.info(JSON.toJSONString(payMothed));
        return BeanRet.create(true, "查询成功", payMothed);
    }


    /**
     * 根据条件id查询PayMothed一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询PayMothed一个详情信息", notes = "查询PayMothed一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        PayMothed payMothed = payMothedSV.loadById(id);
        log.info(JSON.toJSONString(payMothed));
        return BeanRet.create(true, "查询成功", payMothed);
    }

    /**
     * 根据条件code查询PayMothed一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询PayMothed一个详情信息", notes = "查询PayMothed一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable String code) {
        if (code == null) {
            return null;
        }
        PayMothed payMothed = payMothedSV.loadByCode(code);
        log.info(JSON.toJSONString(payMothed));
        return BeanRet.create(true, "查询成功", payMothed);
    }


    /**
     * 查询PayMothed信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询PayMothed信息集合", notes = "查询PayMothed信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore PayMothed payMothed, Integer curPage, Integer pageSize) {
        Page<PayMothed> page = new Page<PayMothed>(pageSize, curPage);
        List<PayMothed> payMotheds = payMothedSV.list(payMothed, page.genRowStart(), page.getPageSize());
        page.setVoList(payMotheds);
        int total = payMothedSV.count(payMothed);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询PayMothed信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询PayMothed信息集合", notes = "查询PayMothed信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(Long id, String code, Integer curPage, Integer pageSize) {
        Page<PayMothed> page = new Page<PayMothed>(pageSize, curPage);
        List<PayMothed> payMotheds = payMothedSV.list(id, code, page.genRowStart(), page.getPageSize());
        page.setVoList(payMotheds);
        int total = payMothedSV.count(id, code);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计PayMothed信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计PayMothed信息数量根据主键", notes = " 统计PayMothed信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String code) {
        return payMothedSV.count(id, code);
    }

    /**
     * 统计PayMothed信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计PayMothed信息数量", notes = "统计PayMothed信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "支付方式", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore PayMothed payMothed) {
        if (payMothed == null) {
            return payMothedSV.count(new HashMap());
        } else {
            return payMothedSV.count(payMothed);
        }
    }


    /**
     * 创建PayMothed
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建PayMothed", notes = "创建PayMothed")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "支付方式", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore PayMothed payMothed) {
        payMothedSV.save(payMothed);
        return BeanRet.create(true, "创建成功", payMothed);
    }


    /**
     * 修改PayMothed
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改PayMothed", notes = "修改PayMothed")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "支付方式", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore PayMothed payMothed) {
        payMothedSV.modify(payMothed);
        return BeanRet.create(true, "修改成功", payMothed);
    }

    /**
     * 删除PayMothed
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除PayMothed", notes = "删除PayMothed")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String code) {
        payMothedSV.delete(id, code);
        return BeanRet.create(true, "删除PayMothed成功");
    }

}
